package cn.itcast.bos.consumer;

import java.util.List;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Component;

import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse.SmsSendDetailDTO;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;

import cn.itcast.bos.utils.SmsDemoUtils;
import cn.itcast.bos.utils.SmsDemoUtils2;
@Component("queueConsumer2")
public class CourierConsumer implements MessageListener{

	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage)message;
		try {
			String telephone = mapMessage.getString("telephone");
			String num = mapMessage.getString("num"); // 验证码
			String sendAddres = mapMessage.getString("sendAddress"); // 寄件人地址
			//String sendName = mapMessage.getString("sendName"); // 寄件人
			String sendMobile = mapMessage.getString("sendMobile"); // 寄件人电话
			String sendMobileMsg = mapMessage.getString("sendMobileMsg"); // 快递员稍话
			// 内容可以新建一个模板，然后发送新的短信内容即可。
			SendSmsResponse sendSmsResponse = SmsDemoUtils2.sendSms(telephone, num, sendAddres, "校长", sendMobile, sendMobileMsg);
			String sendSms = sendSmsResponse.getCode();
			//String sendSms = "OK";
			if(sendSms.equals("OK")){
				// 发送成功
//				System.out.println("发送短信成功,手机号：" + telephone);
//				System.out.println("速运快递 短信序号："+num+",取件地址："+sendAddres+",联系人："+",手机:"+sendMobile+"，快递员捎话："+sendMobileMsg+"");
				QuerySendDetailsResponse querySendDetails = SmsDemoUtils.querySendDetails(sendSmsResponse.getBizId());
				
				List<SmsSendDetailDTO> smsSendDetailDTOs = querySendDetails.getSmsSendDetailDTOs();
				for(QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO :smsSendDetailDTOs){
					System.out.println("短信内容："+smsSendDetailDTO.getContent());
				}
			}
		} catch (Exception e) {
			System.out.println("发送短信失败！！！");
			e.printStackTrace();
		}
		
	}

	
}
